package com.yang.drawcard;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.yang.drawcard.base.BaseActivity;
import com.yang.drawcard.book.BookActivity;
import com.yang.drawcard.image.ImagePicActivity;
import com.yang.drawcard.utils.ViewUtil;
import com.yang.drawcard.video.VideoActivity;
import com.yang.drawcard.web.newbrowser.BrowserPicActivity;
import com.yang.drawcard.web.oldbrowser.WebPicActivity;

import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private RelativeLayout backBtn;
    private RelativeLayout confirmBtn;
    private AppCompatTextView confirmTv;
    private AppCompatTextView backTv;
    private AppCompatTextView titleTv;

    private LinearLayoutCompat mainRlLongpic1;
    private ImageView mainImgLongpic1;
    private LinearLayoutCompat mainRlLongpic2;
    private ImageView mainImgLongpic2;
    private LinearLayoutCompat mainRlLongpic3;
    private ImageView mainImgLongpic3;
    private LinearLayoutCompat mainRlLongpic4;
    private ImageView mainImgLongpic4;
    private LinearLayoutCompat mainRlMine;
    private ImageView mainImgMine;
    private LinearLayoutCompat mainRlEditip;
    private ImageView mainImgEditip;
    private LinearLayoutCompat mainRlPic;
    private ImageView mainImgPic;
    private LinearLayoutCompat mainRlFriend;
    private ImageView mainImgFriend;
    private LinearLayoutCompat mainRlSports;
    private ImageView mainImgSports;
    private LinearLayoutCompat mainRlMath;
    private ImageView mainImgMath;
    private LinearLayoutCompat mainRlBook;
    private ImageView mainImgBook;
    private LinearLayoutCompat mainRlVideo;
    private ImageView mainImgVideo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 沉浸式
        setStatusBar();

        initView();

        initData();
    }


    private void initView() {

        backBtn = (RelativeLayout) findViewById(R.id.top_dd_navigation_rl_back);
        confirmBtn = (RelativeLayout) findViewById(R.id.top_dd_navigation_rl_confirm);
        confirmTv = (AppCompatTextView) findViewById(R.id.top_dd_navigation_bt_confirm);
        backTv = (AppCompatTextView) findViewById(R.id.top_dd_navigation_bt_back);
        titleTv = (AppCompatTextView) findViewById(R.id.top_dd_navigation_tv_title);
        backBtn.setVisibility(View.INVISIBLE);
        confirmBtn.setVisibility(View.INVISIBLE);
        // confirmBtn.setOnClickListener(this);
        // backBtn.setOnClickListener(this);


        mainRlLongpic1 = (LinearLayoutCompat) findViewById(R.id.main_rl_longpic1);
        mainImgLongpic1 = (ImageView) findViewById(R.id.main_img_longpic1);
        mainRlLongpic2 = (LinearLayoutCompat) findViewById(R.id.main_rl_longpic2);
        mainImgLongpic2 = (ImageView) findViewById(R.id.main_img_longpic2);
        mainRlLongpic3 = (LinearLayoutCompat) findViewById(R.id.main_rl_longpic3);
        mainImgLongpic3 = (ImageView) findViewById(R.id.main_img_longpic3);
        mainRlLongpic4 = (LinearLayoutCompat) findViewById(R.id.main_rl_longpic4);
        mainImgLongpic4 = (ImageView) findViewById(R.id.main_img_longpic4);
        mainRlMine = (LinearLayoutCompat) findViewById(R.id.main_rl_mine);
        mainImgMine = (ImageView) findViewById(R.id.main_img_mine);
        mainRlEditip = (LinearLayoutCompat) findViewById(R.id.main_rl_editip);
        mainImgEditip = (ImageView) findViewById(R.id.main_img_editip);
        mainRlPic = (LinearLayoutCompat) findViewById(R.id.main_rl_pic);
        mainImgPic = (ImageView) findViewById(R.id.main_img_pic);
        mainRlFriend = (LinearLayoutCompat) findViewById(R.id.main_rl_friend);
        mainImgFriend = (ImageView) findViewById(R.id.main_img_friend);
        mainRlSports = (LinearLayoutCompat) findViewById(R.id.main_rl_sports);
        mainImgSports = (ImageView) findViewById(R.id.main_img_sports);
        mainRlMath = (LinearLayoutCompat) findViewById(R.id.main_rl_math);
        mainImgMath = (ImageView) findViewById(R.id.main_img_math);
        mainRlBook = (LinearLayoutCompat) findViewById(R.id.main_rl_book);
        mainImgBook = (ImageView) findViewById(R.id.main_img_book);
        mainRlVideo = (LinearLayoutCompat) findViewById(R.id.main_rl_video);
        mainImgVideo = (ImageView) findViewById(R.id.main_img_video);





        mainRlBook.setOnClickListener(this);
        mainRlVideo.setOnClickListener(this);
        mainRlPic.setOnClickListener(this);
        mainRlFriend.setOnClickListener(this);
        mainRlSports.setOnClickListener(this);
        mainRlMath.setOnClickListener(this);
        mainRlLongpic1.setOnClickListener(this);
        mainRlLongpic2.setOnClickListener(this);
        mainRlLongpic3.setOnClickListener(this);
        mainRlLongpic4.setOnClickListener(this);
        mainRlMine.setOnClickListener(this);
        mainRlEditip.setOnClickListener(this);
    }

    private void initData() {
        titleTv.setText("首页");

        Glide.with(this).load("https://img.166.net/reunionpub/yx/auto/20240207/112459-68r7ls945n.jpeg?imageView&tostatic=0&thumbnail=272y272").into(mainImgLongpic1);
        Glide.with(this).load("https://img.166.net/reunionpub/yx/auto/20240207/112500-e59mcn7q1j.jpeg?imageView&tostatic=0&thumbnail=272y272").into(mainImgLongpic2);
        Glide.with(this).load("https://img.166.net/reunionpub/yx/auto/20240207/112502-j807rdt4bn.jpeg?imageView&tostatic=0&thumbnail=272y272").into(mainImgLongpic3);
        Glide.with(this).load("https://img.166.net/reunionpub/yx/auto/20240207/112504-3lpfg7iec2.jpeg?imageView&tostatic=0&thumbnail=272y272").into(mainImgLongpic4);
        Glide.with(this).load("https://img.166.net/reunionpub/yx/auto/20240207/112507-m2w38d19yf.jpeg?imageView&tostatic=0&thumbnail=272y272").into(mainImgMine);

        Glide.with(this).load("https://wx2.sinaimg.cn/mw690/006HyQKGgy1hmmzp5d5e0j30rs0rsq7l.jpg").into(mainImgEditip);
        Glide.with(this).load("https://wx3.sinaimg.cn/mw690/006HyQKGgy1hmmzp6uja4j30rs0rstbo.jpg").into(mainImgPic);
        Glide.with(this).load("https://wx3.sinaimg.cn/mw690/006HyQKGgy1hmmzp8kntwj30rs0rsaea.jpg").into(mainImgFriend);
        Glide.with(this).load("https://wx4.sinaimg.cn/mw690/006HyQKGgy1hmmzpc7nrlj30rs0rsjwf.jpg").into(mainImgSports);
        Glide.with(this).load("https://wx1.sinaimg.cn/mw690/006HyQKGgy1hmmzpazzyzj30rs0rswip.jpg").into(mainImgMath);

        Glide.with(this).load("https://wx2.sinaimg.cn/mw690/006HyQKGgy1hmmzp17vodj30rs0rsdkg.jpg").into(mainImgBook);
        Glide.with(this).load("https://wx2.sinaimg.cn/mw690/006HyQKGgy1hmmzp2n2yhj30rs0rsgpg.jpg").into(mainImgVideo);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.main_rl_longpic1:// 长图1
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent longpic1Intent = new Intent(MainActivity.this, WebPicActivity.class);
                longpic1Intent.putExtra("url", "https://official-account-system.fp.ps.netease.com/file/65bdd7f64709d5acbbd03e9c986DffXz05?imageView&tostatic=0&thumbnail=1500x0");
                longpic1Intent.putExtra("title", "");//
                startActivity(longpic1Intent);

                break;
            case R.id.main_rl_longpic2:// 长图2
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent longpic2Intent = new Intent(MainActivity.this, WebPicActivity.class);
                longpic2Intent.putExtra("url", "https://official-account-system.fp.ps.netease.com/file/658a8378c38c015e7057977fbeQGMciC05?imageView&tostatic=0&thumbnail=1500x0");
                longpic2Intent.putExtra("title", "");//
                startActivity(longpic2Intent);

                break;
            case R.id.main_rl_longpic3:// 长图3
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent longpic3Intent = new Intent(MainActivity.this, WebPicActivity.class);
                longpic3Intent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20230920/190404-3saiy60muc.png?imageView&tostatic=0&thumbnail=1500x0");
                longpic3Intent.putExtra("title", "");//
                startActivity(longpic3Intent);

                break;
            case R.id.main_rl_longpic4:// 长图4
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent longpic4Intent = new Intent(MainActivity.this, WebPicActivity.class);
                longpic4Intent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20230807/183129-zb17hks0yl.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                longpic4Intent.putExtra("title", "");//
                startActivity(longpic4Intent);

                break;
            case R.id.main_rl_mine:// 我的
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent mineIntent = new Intent(MainActivity.this, WebPicActivity.class);
                mineIntent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20230317/220723-q9nf6jihsv.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                mineIntent.putExtra("title", "");//
                startActivity(mineIntent);

                break;

            case R.id.main_rl_editip:// 修改IP
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent editipIntent = new Intent(MainActivity.this, BrowserPicActivity.class);
                editipIntent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20230116/164545-m85nk46rti.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                editipIntent.putExtra("title", "");//
                startActivity(editipIntent);

                break;

            case R.id.main_rl_pic:// 图片
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent picIntent = new Intent(MainActivity.this, ImagePicActivity.class);
                // picIntent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20221225/155618-h376nw45cz.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                // picIntent.putExtra("title", "");//
                startActivity(picIntent);

                break;
            case R.id.main_rl_friend:// 交友
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent friendIntent = new Intent(MainActivity.this, BrowserPicActivity.class);
                friendIntent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20220926/212143-lb6gv41fah.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                friendIntent.putExtra("title", "");//
                startActivity(friendIntent);

                break;
            case R.id.main_rl_sports:// 体育
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent sportsIntent = new Intent(MainActivity.this, BrowserPicActivity.class);
                sportsIntent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20220808/181814-m54cgsrpf3.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                sportsIntent.putExtra("title", "");//
                startActivity(sportsIntent);

                break;
            case R.id.main_rl_math:// 傻瓜回答
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent mathIntent = new Intent(MainActivity.this, BrowserPicActivity.class);
                mathIntent.putExtra("url", "https://img.166.net/reunionpub/ds/kol/20220616/185038-at4ulcigb6.jpeg?imageView&tostatic=0&thumbnail=1500x0");
                mathIntent.putExtra("title", "");//
                startActivity(mathIntent);

                break;

            case R.id.main_rl_book:// 图书
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent intent = new Intent(this, BookActivity.class);
                startActivity(intent);

                break;
            case R.id.main_rl_video:// 视频
                if (ViewUtil.isDoubleClick(v.getId(), 2500))
                    return;

                Intent VideoIntent = new Intent(this, VideoActivity.class);
                startActivity(VideoIntent);

                break;

        }
    }

    /**
     * 处理回退事件
     *
     * @return
     */
    @Override
    public void onBackPressedSupport() {
        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
            MainActivity.this.finish();
        } else {
            TOUCH_TIME = System.currentTimeMillis();
            Toast.makeText(MainActivity.this, "再按一次返回键退出应用", Toast.LENGTH_SHORT).show();
        }

    }
}